//data/models/ApiResponse.kt

package com.example.xxcjgl.data.models

import com.google.gson.annotations.SerializedName

/**
 * 通用API响应模型
 * @param T 数据类型
 * @property success 请求是否成功
 * @property message 响应消息
 * @property data 响应数据
 * @property code 状态码
 * @property timestamp 时间戳
 */
// 在 ApiResponse.kt 中
data class ApiResponse<T>(
    @SerializedName("success")
    val success: Boolean,

    @SerializedName("message")
    val message: String,

    @SerializedName("data")
    val data: T? = null,

    @SerializedName("code")
    val code: Int = 0,

    @SerializedName("timestamp")
    val timestamp: Long = System.currentTimeMillis()
) {
    companion object {
        fun <T> success(data: T? = null, message: String = "成功"): ApiResponse<T> {
            return ApiResponse(
                success = true,
                message = message,
                data = data,
                code = 200,
                timestamp = System.currentTimeMillis()
            )
        }

        fun <T> error(message: String, code: Int = -1): ApiResponse<T> {
            return ApiResponse(
                success = false,
                message = message,
                data = null,
                code = code,
                timestamp = System.currentTimeMillis()
            )
        }
    }

    // 添加便捷属性
    val isSuccess: Boolean get() = success
    val hasData: Boolean get() = data != null
}

/**
 * 分页数据模型
 */
data class PaginatedResponse<T>(
    @SerializedName("data")
    val data: List<T>,

    @SerializedName("total")
    val total: Int,

    @SerializedName("page")
    val page: Int,

    @SerializedName("page_size")
    val pageSize: Int,

    @SerializedName("total_pages")
    val totalPages: Int
) {
    val hasNext: Boolean
        get() = page < totalPages

    val hasPrevious: Boolean
        get() = page > 1
}

/**
 * 文件上传响应
 */
data class FileUploadResponse(
    @SerializedName("file_url")
    val fileUrl: String,

    @SerializedName("file_name")
    val fileName: String,

    @SerializedName("file_size")
    val fileSize: Long
)

/**
 * 系统统计信息
 */
data class SystemStats(
    @SerializedName("total_students")
    val totalStudents: Int,

    @SerializedName("total_scores")
    val totalScores: Int,

    @SerializedName("encrypted_count")
    val encryptedCount: Int,

    @SerializedName("today_added")
    val todayAdded: Int
)